home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_vim.idb / usr / freeware / share / vim / doc / visual.txt.z / visual.txt
Encoding:
Text File  |  1998-10-28  |  10.9 KB  |  277 lines

  1. *visual.txt*    For Vim version 5.0.  Last modification: 1998 Feb 07
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Visual mode                    *Visual-mode* *visual-mode*
  8.  
  9. Visual mode is a flexible and easy way to select a piece of text for an
  10. operator.  It is the only way to select a block of text.
  11.  
  12. 1. Using Visual mode            |visual-use|
  13. 2. Starting and stopping Visual mode    |visual-start|
  14. 3. Changing the Visual area        |visual-change|
  15. 4. Operating on the Visual area        |visual-operators|
  16. 5. Repeating                |visual-repeat|
  17. 6. Examples                |visual-examples|
  18.  
  19. {Vi has no Visual mode, the name "visual" is used for Normal mode, to
  20. distinguish it from Ex mode}
  21.  
  22. ==============================================================================
  23. 1. Using Visual mode                    *visual-use*
  24.  
  25. Using Visual mode consists of three parts:
  26. 1. Mark the start of the text with "v", "V" or CTRL-V.
  27.    The character under the cursor will be used as the start.
  28. 2. Move to the end of the text.
  29.    The text from the start of the Visual mode up to and including the
  30.    character under the cursor is highlighted.
  31. 3. Hit an operator.
  32.    The highlighted characters will be operated upon.
  33.  
  34. The 'highlight' option can be used to set the display mode to use for
  35. highlighting in Visual mode.
  36.  
  37. The highlighted text includes the character under the cursor.  On terminals
  38. where it is possible to make the cursor invisible the cursor position is
  39. also highlighted.  On terminals where this is not possible the cursor is
  40. displayed normally.  If your cursor cannot be made invisible and you want Vim
  41. to highlight the character under the cursor anyway, you could set the 't_cv'
  42. and 't_ci' options to something harmless, for example:
  43. >    :set t_cv=^[^[ t_ci=^[^[
  44.  
  45. With "v" the text before the start position and after the end position will
  46. not be highlighted.  However, All uppercase and non-alpha operators, except
  47. "~", will work on whole lines anyway.  See the list of operators below.
  48.  
  49.                             *visual-block*
  50. With CTRL-V (blockwise Visual mode) the highlighted text will be a rectangle
  51. between start position and the cursor.  However, some operators work on whole
  52. lines anyway (see the list below).  The change and substitute operators will
  53. delete the highlighted text and then start insertion at the top left
  54. position.
  55.  
  56. ==============================================================================
  57. 2. Starting and stopping Visual mode            *visual-start*
  58.  
  59.                         *v* *characterwise-visual*
  60. v            start Visual mode per character.
  61.  
  62.                         *V* *linewise-visual*
  63. V            start Visual mode linewise.
  64.  
  65.                         *CTRL-V* *blockwise-visual*
  66. CTRL-V            start Visual mode blockwise.
  67.  
  68. If you use <Esc>, click the left mouse button or use any command that
  69. does a jump to another buffer while in Visual mode, the highlighting stops
  70. and no text is affected.  Also when you hit "v" in characterwise Visual mode,
  71. "CTRL-V" in blockwise Visual mode or "V" in linewise Visual mode.  If you hit
  72. CTRL-Z the highlighting stops and the editor is suspended or a new shell is
  73. started |CTRL-Z|.
  74.  
  75.               new mode after typing:        *v_v* *v_CTRL-V* *v_V*
  76. old mode             "v"              "CTRL-V"               "V"    ~
  77.  
  78. Normal              Visual         blockwise Visual       linewise Visual
  79. Visual              Normal         blockwise Visual       linewise Visual
  80. blockwise Visual    Visual         Normal                 linewise Visual
  81. linewise Visual     Visual         blockwise Visual       Normal
  82.  
  83.                             *gv* *v_gv*
  84. gv            Start Visual mode with the same area as the previous
  85.             area and the same mode.  In Visual mode the current and
  86.             the previous Visual area are exchanged.
  87.  
  88.                             *<LeftMouse>*
  89. <LeftMouse>        Set the current cursor position.  If Visual mode is
  90.             active it is stopped.  Only when 'mouse' option is
  91.             contains 'n' or 'a'.  If the position is within 'so'
  92.             lines from the last line on the screen the text is
  93.             scrolled up.  If the position is within 'so' lines from
  94.             the first line on the screen the text is scrolled
  95.             down.
  96.  
  97.                             *<RightMouse>*
  98. <RightMouse>        Start Visual mode if it is not active.  The text from
  99.             the cursor position to the position of the click is
  100.             highlighted.  If Visual mode was already active move
  101.             the start or end of the highlighted text, which ever
  102.             is closest, to the position of the click.  Only when
  103.             'mouse' option contains 'n' or 'a'.
  104.  
  105.                             *<LeftRelease>*
  106. <LeftRelease>        This works like a <LeftMouse>, if it is not a
  107.             the same position as <LeftMouse>.  In an xterm you
  108.             won't see the selected area until the button is
  109.             released.  Only when 'mouse' option contains 'n' or
  110.             'a'.
  111.  
  112. If Visual mode is not active and the "v", "V" or CTRL-V is preceded with a
  113. count, the size of the previously highlighted area is used for a start.  You
  114. can then move the end of the highlighted area and give an operator.  The type
  115. of the old area is used (character, line or blockwise).
  116. - Linewise Visual mode: The number of lines is multiplied with the count.
  117. - Blockwise Visual mode: The number of lines and columns is multiplied with
  118.   the count.
  119. - Normal Visual mode within one line: The number of characters is multiplied
  120.   with the count.
  121. - Normal Visual mode with several lines: The number of lines is multiplied
  122.   with the count, in the last line the same number of characters is used as
  123.   in the last line in the previously highlighted area.
  124. The start of the text is the Cursor position.  If the "$" command was used as
  125. one of the last commands to extend the highlighted text, the area will be
  126. extended to the rightmost column of the longest line.
  127.  
  128. If you want to highlight exactly the same area as the last time, you can use
  129. "gv" |gv| |v_gv|.
  130.  
  131.                             *v_CTRL-C*
  132. CTRL-C            In Visual mode: Stop Visual mode.  When insert mode is
  133.             pending (the mode message shows
  134.             "-- (insert) VISUAL --"), it is also stopped.
  135.  
  136. ==============================================================================
  137. 3. Changing the Visual area                *visual-change*
  138.  
  139.                             *v_o*
  140. o            Go to Other end of highlighted text: The current
  141.             cursor position becomes the start of the highlighted
  142.             text and the cursor is moved to the other end of the
  143.             highlighted text.  The highlighted area remains the
  144.             same.
  145.  
  146.                             *v_O*
  147. O            Go to Other end of highlighted text.  This is like
  148.             "o", but in Visual block mode the cursor moves to the
  149.             other corner in the same line.  When the corner is at
  150.             a character that occupies more than one position on
  151.             the screen (e.g., a <Tab>), the highlighted text may
  152.             change.
  153.  
  154. When the "$" command is used with blockwise Visual mode, the right end of the
  155. highlighted text will be determined by the longest highlighted line.  This
  156. stops when a motion command is used that does not move straight up or down.
  157.  
  158. For moving the end of the block many commands can be used, but you cannot
  159. use Ex commands, commands that make changes or abandon the file.  Commands
  160. (starting with) ".pPiIaAO&", CTRL-^, "Z", CTRL-], CTRL-T, CTRL-R, CTRL-I
  161. and CTRL-O cause a beep and Visual mode continues.
  162.  
  163.  
  164. ==============================================================================
  165. 4. Operating on the Visual area                *visual-operators*
  166.  
  167. The operators that can be used are:
  168.     ~    switch case                    |v_~|
  169.     d    delete                        |v_d|
  170.     c    change                        |v_c|
  171.     y    yank                        |v_y|
  172.     >    shift right (1)(*)                |v_>|
  173.     <    shift left (1)(*)                |v_<|
  174.     !    filter through external command (1)        |v_!|
  175.     =    filter through 'equalprg' option command (1)    |v_=|
  176.     gq    format lines to 'textwidth' length (1)        |v_gq|
  177.  
  178. The objects that can be used are:
  179.     aw    a word (with white space)            |v_aw|
  180.     iw    inner word                    |v_iw|
  181.     aW    a WORD (with white space)            |v_aW|
  182.     iW    inner WORD                    |v_iW|
  183.     as    a sentence (with white space)            |v_as|
  184.     is    inner sentence                    |v_is|
  185.     ap    a paragraph (with white space)            |v_ap|
  186.     ip    inner paragraph                    |v_ip|
  187.     ab    a () block (with braces)            |v_ab|
  188.     ib    inner () block                    |v_ib|
  189.     aB    a {} block (with brackets)            |v_aB|
  190.     iB    inner {} block                    |v_iB|
  191.  
  192. Additionally the following commands can be used:
  193.     :    start ex command for highlighted lines (1)    |v_:|
  194.     r    change                        |v_r|
  195.     s    change                        |v_s|
  196.     C    change (2)                    |v_C|
  197.     S    change (2)                    |v_S|
  198.     R    change (2)                    |v_R|
  199.     x    delete                        |v_x|
  200.     D    delete (3)                    |v_D|
  201.     X    delete (2)                    |v_X|
  202.     Y    yank (2)                    |v_Y|
  203.     J    join (1)                    |v_J|
  204.     U    make uppercase                    |v_U|
  205.     u    make lowercase                    |v_u|
  206.     ^]    find tag                    |v_CTRL-]|
  207.  
  208. (1): Always whole lines, see |:visual_example|.
  209. (2): Whole lines when not using CTRL-V.
  210. (3): Whole lines when not using CTRL-V, delete until the end of the line when
  211.      using CTRL-V.
  212. (*): In a future a blockwise shift will move the block only, not whole
  213.      lines.
  214.  
  215. Note that the ":vmap" command can be used to specifically map keys in Visual
  216. mode.
  217.  
  218. If you want to give a register name using the """ command, do this just before
  219. typing the operator character: "v{move-around}"xd".
  220.  
  221. If you want to give a count to the command, do this just before typing the
  222. operator character: "v{move-around}3>" (move lines 3 indents to the right).
  223.  
  224.                             *{move-around}*
  225. The {move-around} is any sequence of movement commands.  Note the difference
  226. with {motion}, which is only ONE movement command.
  227.  
  228. ==============================================================================
  229. 5. Repeating                        *visual-repeat*
  230.  
  231. When repeating a Visual mode operator, the operator will be applied to the
  232. same amount of text as the last time:
  233. - Linewise Visual mode: The same number of lines.
  234. - Blockwise Visual mode: The same number of lines and columns.
  235. - Normal Visual mode within one line: The same number of characters.
  236. - Normal Visual mode with several lines: The same number of lines, in the
  237.   last line the same number of characters as in the last line the last time.
  238. The start of the text is the Cursor position.  If the "$" command was used as
  239. one of the last commands to extend the highlighted text, the repeating will
  240. be applied up to the rightmost column of the longest line.
  241.  
  242.  
  243. ==============================================================================
  244. 6. Examples                        *visual-examples*
  245.  
  246.                             *:visual_example*
  247. Currently the ":" command works on whole lines only.  When you select part of
  248. a line, doing something like ":!date" will replace the whole line.  If you
  249. want only part of the line to be replaced you will have to make a mapping for
  250. it.  In a future release ":" may work on partial lines.
  251.  
  252. Here is an example, to replace the selected text with the output of "date":
  253. >    :vmap _a <Esc>a<CR><Esc>`\<i<CR><Esc>!!date<CR>kJJ
  254.  
  255. (In the <> notation |<>|, when typing it you should type it literally; you
  256. need to remove the 'B' and '<' flags from 'cpoptions')
  257.  
  258. What this does is:
  259. <Esc>        stop Visual mode
  260. a<CR><Esc>    break the line after the Visual area
  261. `\<        jump to the start of the Visual area
  262. i<CR><Esc>    break the line before the Visual area
  263. !!date<CR>    filter the Visual text through date
  264. kJJ        Join the lines again
  265.  
  266.                             *visual-search*
  267. Here is an idea for a mapping that makes it possible to do a search for the
  268. selected text:
  269. >    :vmap X y/<C-R>"<CR>
  270.  
  271. (In the <> notation |<>|, when typing it you should type it literally; you
  272. need to remove the 'B' and '<' flags from 'cpoptions')
  273.  
  274. Note that special characters (like '.' and '*') will cause problems.
  275.  
  276.  vim:tw=78:ts=8:sw=8:
  277.